package main.model.critters.genetics;

import java.util.HashMap;
import java.util.Map;

public class DefaultMorphology implements Morphology {
	private Map<Phenotype, Integer> morphMap = new HashMap<Phenotype, Integer>();
	
	public DefaultMorphology(Sex sex, Chromosome chromosomeX, Chromosome chromosomeY){
		for (Phenotype p : Phenotype.values()){
			Sex gs = Sex.NONE;
			if(p.getDimorphism()){
				gs = sex;
			}
			
			Gene gX = chromosomeX.getGene(GeneType.findGeneType(p,gs));
			Gene gY = chromosomeY.getGene(GeneType.findGeneType(p,gs));	
			
			if(gX.getDominance() > gY.getDominance()){
				morphMap.put(p,gX.getEffect());
			}else{
				morphMap.put(p,gY.getEffect());
			}
		}
	}

    public int getTotalMorphologyCost(){
        int totalCost = 0;
        for(Integer value : morphMap.values()){
            totalCost += value;
        }
        return totalCost;
    }

	public int getCamouflage() {
		int mod = (-1*(morphMap.get(Phenotype.SEXUALDISPLAY)/2))+
                (-1*(morphMap.get(Phenotype.SIZE)/4));
		return morphMap.get(Phenotype.CAMOFLAGE)+mod;
	}

	public int getDefence() {
		int mod = morphMap.get(Phenotype.SIZE)/2;
		return morphMap.get(Phenotype.DEFENCE)+mod;
	}

	public int getAttack() {
		int mod = morphMap.get(Phenotype.SIZE)/2;
		return morphMap.get(Phenotype.ATTACK)+mod;
	}
	
	public int getSpeed() {
		int mod = (-1*(morphMap.get(Phenotype.SIZE))+
                (-1*morphMap.get(Phenotype.DEFENCE))/4);
		return morphMap.get(Phenotype.SPEED)+mod;
	}
	
	
	public int getSexualDisplay() {return morphMap.get(Phenotype.SEXUALDISPLAY);}
	
	public int getDisplayAttraction() {return morphMap.get(Phenotype.DISPLAYATTRACTION);}

	public int getHarem() {return morphMap.get(Phenotype.HAREM);}

	public int getHerdWithOffspring() {return morphMap.get(Phenotype.HERDWITHOFFSPRING);}

	public int getHerdWithMother() {return morphMap.get(Phenotype.HERDWITHMOTHER);}

	public int getHerdWithFather() {return morphMap.get(Phenotype.HERDWITHFATHER);}
	
	public int getSize() {return morphMap.get(Phenotype.SIZE);}

	public int getLifespan() {return morphMap.get(Phenotype.LIFESPAN);}

	public int getSensory() {return morphMap.get(Phenotype.SENSORY);}

	public int getLitterSize() {return morphMap.get(Phenotype.LITTERSIZE);}

	public int getFavTerrain() {return morphMap.get(Phenotype.FAVTERRAIN);}

	public int getDiet() {return morphMap.get(Phenotype.DIET);}

	public int getFear() {return morphMap.get(Phenotype.FEAR);}

	public int getHerdSize() {return morphMap.get(Phenotype.HERDSIZE);}
}
